import numpy as np
import pandas as pd
import sklearn as sk
from sklearn.datasets import load_iris
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

# 导入鸢尾花数据集
iris = load_iris()
print('iris数据集特征')
print(iris.data[:10])

print('iris数据集标签')
print(iris.target)

# 使用train_test_split来分割数据集
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=42)

# 创建高斯朴素贝叶斯分类器实例
clf = GaussianNB()

# 训练模型
clf.fit(X_train, y_train)

# 进行预测
predictions = clf.predict(X_test)

# 打印预测结果的前10个
print('预测结果前10个数据：')
print(predictions[:10])

# 计算准确率
print('准确率：')
print('Accuracy: %s' % accuracy_score(y_test, predictions))